//
//  SHGDIscoverSerachView.swift
//  -微博准备
//
//  Created by 孙护国 on 16/4/8.
//  Copyright © 2016年 孙护国. All rights reserved.
//

import UIKit

class SHGDIscoverSerachView: UIView {

    @IBOutlet weak var rightCons: NSLayoutConstraint!
    @IBOutlet weak var cancelBtn: UIButton!

    @IBOutlet weak var textView: SHGTextField!
    @IBAction func cancelBtnDidClick(sender: AnyObject) {
        textView.resignFirstResponder()
        rightCons.constant=0
        UIView.animateWithDuration(0.25) { () -> Void in
            self.layoutIfNeeded()
        }
    }
    
 
    @IBAction func textBeginEdit(sender: AnyObject) {
        rightCons.constant=cancelBtn.frame.width
        UIView.animateWithDuration(0.25) { () -> Void in
            self.layoutIfNeeded()
    }

    }
    override func awakeFromNib() {
        self.frame=CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: self.bounds.height)
        self.textView.leftView = UIImageView(image: UIImage(named: "searchbar_textfield_search_icon"))
         self.textView.leftView?.frame = CGRect(x: 0, y: 0, width: self.bounds.height, height: self.bounds.height)
        //设置图片的模式
        self.textView.leftView?.contentMode = .Center
        //设置图片的显示方式
        self.textView.leftViewMode = .Always
        //设置圆角
                textView.layer.cornerRadius = 17
                textView.layer.masksToBounds = true
        textView.layer.borderWidth=2
        textView.layer.borderColor=UIColor.orangeColor().CGColor
    }
    class func loadSearchView()->SHGDIscoverSerachView{
    let v = NSBundle.mainBundle().loadNibNamed("SHGDIscoverSerachView", owner: nil, options: nil).last as!SHGDIscoverSerachView
        return v
    }
}
